package org.jet.emall.prod.transfer;



import org.jet.emall.prod.dto.OrderDTO;
import org.jet.emall.prod.dto.OrderItemDetailViewDTO;

import org.jet.emall.prod.vo.OrderItemDetailViewVO;
import org.jet.emall.prod.vo.OrderVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.LinkedList;
import java.util.List;

/**
 * @author xiaozai
 * @version 1.0
 * @date 2020-04-25 12:36
 */
@Mapper
public interface OrderVoTransfer {

    OrderVoTransfer INSTANCE = Mappers.getMapper(OrderVoTransfer.class) ;



    /**
     *
     * @param dtoList
     * @return
     */
    default List<OrderVO> toVoList(List<OrderDTO> dtoList){
        List<OrderVO> voList = new LinkedList<>();
        for(OrderDTO dto : dtoList){
            OrderVO vo = toVo(dto);
            voList.add(vo);
            vo.setItems(toItemVoList(dto.getItems()));
        }
        return voList;
    }


    /**
     *
     * @param items
     * @return
     */
    List<OrderItemDetailViewVO> toItemVoList(List<OrderItemDetailViewDTO> items);


    /**
     *
     * @param dto
     * @return
     */
    @Mapping(target = "items",ignore = true)
    OrderVO toVo(OrderDTO dto);

    /**
     *
     * @param dto
     * @return
     */

    default OrderVO toVoWithItems(OrderDTO dto){
        OrderVO orderVO = toVo(dto);
        orderVO.setItems(toItemVoList(dto.getItems()));
        return orderVO;
    }

}
